<template>
    <!-- 总账-财务处理-记账  -->
    <section class="content-box">
    	<div>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form style="display:flex;line-height:5px;justify-content: space-between;">
                <h1>财务处理-记账</h1>
                <el-form-item>
                    <el-button type="primary" @click="jizhang()">
                        <i class="el-icon-check" ></i> 记账
                    </el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <!-- 表格 -->
        <el-table v-if="tableData" :data="tableData"  ref="table" row-key="id" max-height="700"  @selection-change="handleSelectionChange">
        	<el-table-column type="selection" width="55" >
		    </el-table-column>
            <el-table-column prop="VoucherLine_Doc" label="单号" >
            </el-table-column>
            <el-table-column prop="Voucher_DocDate" label="单号日期"  :formatter="formatDate">
            </el-table-column>
            <el-table-column prop="Voucher_Abstracts" label="摘要" width="280">
            </el-table-column>
            <el-table-column prop="TotalJieMoney" label="借方金额" align="right">
            </el-table-column>
            <el-table-column prop="TotalDaiMoney" label="贷方金额" align="right">
            </el-table-column>
            <el-table-column prop="DocStatus" label="状态" >
            </el-table-column>
            <el-table-column prop="Voucher_SourceDocNo" label="来源单号" >
            </el-table-column>
        </el-table>
        <!-- 隐藏页面 -->
		</div>
    </section>
</template>
<script>
import axios from "../../../util/axios";
export default {
    name: 'order',
    data() {
        return {
            tableData: [],
            multipleSelection: [],
        }
    },
    methods: {
    	//时间过滤
    	formatDate(row, column) {
	      return row.Voucher_DocDate.split("T", 1);
	    },
	    //获取 记账 列表
    	getList(){
    		axios
    		.post("getAccount", {
						rows: 20000, // 每页多少条
					})
	    		.then(res => {
		          console.log(res)
		          this.tableData = res.rows;
		        });
    	},
	    handleSelectionChange(val) {
	        this.multipleSelection = val;
	        console.log(this.multipleSelection)
	    },
	    jizhang(){
	    	console.log("jizhang")
	    	let AccountingList = []
	    	for(let i = 0 ; i <this.multipleSelection.length ; i++){
	    		console.log(this.multipleSelection[i].VoucherLine_Doc)
	    		AccountingList.push(this.multipleSelection[i].VoucherLine_Doc)
	    	}
	    	console.log(AccountingList)
	    		axios
	    			.post("KeepAccount",AccountingList)
	    			.then(res => {
			          console.log(res)
			          this.getList()
			          if(res.Success){
			          	this.$message({
			                message: res.Message,
			                type: 'success',
			                duration:2000
		              	})
			          }else{
			          	this.$message({
			                message: res.Message,
			                type: 'error',
			                duration:2000
		              	})
			          }
			        })
			        .catch(err => {
			          console.log(err);		          
			        })
	    			
	    },
    },
    mounted() {
	    this.getList();
	}

}
</script>

